package com.sgb.kjwl.pop;

import android.content.Context;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.Bean;
import com.sgb.kjwl.view.ui.adapter.home.SelectAdapter;
import com.sgb.kjwl.view.widget.MaxHeightRecyclerView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

import androidx.annotation.ColorRes;
import androidx.recyclerview.widget.GridLayoutManager;

public class NeedPopWindow extends BasePopWindow {
    public int mType;
    public SelectAdapter mAdapter;
    private MaxHeightRecyclerView recyclerView;
    public int mPos1;
    public int mPos2;
    public int mPos3;
    public int mPos4;
    public int mPos5;
    public int mPos6;
    public int mPos7;
    public int mPos8;
    public int mPos9;
    public int mPos10;
    public int mPos11;
    public int mPos12;
    public int mPos13;
    public int mPos14;
    public int mPos15;
    public int mPos16;
    public int mPos17;
    public Bean mBean;
    public boolean mIsClick;

    public NeedPopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.need_popwindow;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.goods_type_list);
        mAdapter = new SelectAdapter(mContext, null);
        mAdapter.getCheckDatas();
        mAdapter.setItemSelect(true);
        mAdapter.setDefItem(0);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemClick(new AdapterOnItemClick<Bean>() {
            @Override
            public void onItemClick(Bean bean, int position) {
                mBean = bean;
                mIsClick = true;
                switch (mType) {
                    case 1:
                        mPos1 = position;
                        break;
                    case 2:
                        mPos2 = position;
                        break;
                    case 3:
                        mPos3 = position;
                        break;
                    case 4:
                        mPos4 = position;
                        break;
                    case 5:
                        mPos5 = position;
                        break;
                    case 6:
                        mPos6 = position;
                        break;
                    case 7:
                        mPos7 = position;
                        break;
                    case 8:
                        mPos8 = position;
                        break;
                    case 9:
                        mPos9 = position;
                        break;
                    case 10:
                        mPos10 = position;
                        break;
                    case 11:
                        mPos11 = position;
                        break;
                    case 12:
                        mPos12 = position;
                        break;
                    case 13:
                        mPos13 = position;
                        break;
                    case 14:
                        mPos14 = position;
                        break;
                    case 15:
                        mPos15 = position;
                        break;
                    case 16:
                        mPos16 = position;
                        break;
                    case 17:
                        mPos17 = position;
                        break;

                }
                if (onResultClick != null)
                    onResultClick.result(bean, position, null);
                dissMiss();
            }
        });

        holder.getPop().findViewById(R.id.bg_pop_gray_layout).setOnClickListener(view -> dissMiss());
    }

    public void setData(List<Bean> list) {
        mAdapter.setDatas(list);
    }

    public void setBackground(@ColorRes int color) {
        recyclerView.setBackgroundResource(color);
    }


    public void setDefItem(int position) {
        mAdapter.setDefItem(position);
    }
}
